package com.agriculture.competition.service.impl;

import com.agriculture.common.core.utils.DateUtils;
import com.agriculture.common.core.utils.StringUtils;
import com.agriculture.competition.domain.JaCase;
import com.agriculture.competition.mapper.JaCaseMapper;
import com.agriculture.competition.service.IJaCaseService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 案件Service业务层处理
 *
 * @author agriculture
 * @date 2024-11-14
 */
@Service
public class JaCaseServiceImpl implements IJaCaseService {

    @Autowired
    private JaCaseMapper jaCaseMapper;

    /**
     * 查询案件
     *
     * @param id 案件主键
     * @return 案件
     */
    @Override
    public JaCase selectJaCaseById(Long id) {
        return jaCaseMapper.selectJaCaseById(id);
    }

    /**
     * 查询案件列表
     *
     * @param jaCase 案件
     * @return 案件
     */
    @Override
    public List<JaCase> selectJaCaseList(JaCase jaCase) {
        return jaCaseMapper.selectJaCaseList(jaCase);
    }

    /**
     * 新增案件
     *
     * @param jaCase 案件
     * @return 结果
     */
    @Override
    public int insertJaCase(JaCase jaCase) {
        jaCase.setCreateTime(DateUtils.getNowDate());
        return jaCaseMapper.insertJaCase(jaCase);
    }

    /**
     * 修改案件
     *
     * @param jaCase 案件
     * @return 结果
     */
    @Override
    public int updateJaCase(JaCase jaCase) {
        jaCase.setUpdateTime(DateUtils.getNowDate());
        return jaCaseMapper.updateJaCase(jaCase);
    }

    /**
     * 批量删除案件
     *
     * @param ids 需要删除的案件主键
     * @return 结果
     */
    @Override
    public int deleteJaCaseByIds(Long[] ids) {
        return jaCaseMapper.deleteJaCaseByIds(ids);
    }

    /**
     * 删除案件信息
     *
     * @param id 案件主键
     * @return 结果
     */
    @Override
    public int deleteJaCaseById(Long id) {
        return jaCaseMapper.deleteJaCaseById(id);
    }

    @Override
    public int updateJaCaseReadCount(JaCase jaCase) {
        String remark = jaCase.getRemark();
        if (StringUtils.isEmpty(remark)) {
            remark = "0";
        }
        jaCase.setRemark(Integer.valueOf(remark) + 1 + "");
        return jaCaseMapper.updateJaCase(jaCase);
    }
}
